'''
查找一个文件中最长的行，输出长度
• 考虑文件比较大
• 考虑代码精简
'''
#生成一个大文件:
import string
import random
m=0
with open('big.txt','a') as f:
    for i in range(1001):
        f.write(("".join(random.choices(string.ascii_lowercase,k=random.randint(1,50)))+"\n"))

def max_length():
    global m
    with open('big.txt','r') as fp:
        while 1:
            r=fp.readlines(1000)
            if r:
                yield r
            else:
                return
for i in max_length():
    for j in i:
        if m < len(j):
            m = len(j)
print("向后读取50个字符所在的行,当前最长行为:",end='')
print(m)
